#测试模板广场页面
from time import sleep
from common.Untils import WJDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
class WJTemplate:
    url = ""
    driver = ""

    def __init__(self):
        #WJLogin.WJLogin().LoginSuccess()
        self.url = "http://8.155.1.153:8081/template"
        self.driver = WJDriver.driver
        self.driver.get(self.url)
        WJDriver.Login()
        #sleep(2)
        #点击我的模板广场
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/aside/div/div[1]/ul/li[5]").click()

    def TestByTemplateFunction(self):
        # self.driver.find_element(By.CSS_SELECTOR,"").send_keys()
        # self.driver.find_element(By.CSS_SELECTOR,"").click()
        #1.测试共有库#############################################################################
        #正确填写模板名称，点击搜索模板
            #输入要搜索的模板
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[2]/div/div/div/div/div/span/span/input").send_keys("测试")
            #点击搜模板
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[2]/div/div/div/div/div/span/span/span/button").click()
        #111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
        #点击添加模板，进入模板编辑页面编辑好内容，点击保存到公有库，点击保存，填写提示框再点击保存
            #点击添加模板
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[1]/span/div/div/button").click()
            #输入模板名称
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[2]/div/div/div[1]/div[2]/div[1]/div/pre/div[1]/p").send_keys("自动化测试"+WJDriver.name)
            #输入模板内容
        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div")))
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div").click()
            #点击保存
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[5]").click()
            #弹出窗口，输入分类
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[2]/form/div[2]/div/div[2]/div/div/div/div/span[1]/input").send_keys("自动化测试")
        #self.driver.find_element(By.XPATH,"/html/body/div[6]/div/div/div/div[2]/div/div/div/div[3]/div").click()
            #点击添加到公有库
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[2]/form/div[4]/div/div/div/div/label/span[1]/input").click()
        sleep(1)
            #点击保存
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[2]").click()
            #点击关闭
        sleep(1)
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[1]").click()
        print("模板广场页面：公有库1正常")
        #222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
        #填写模板名称，不填写分类
            #点击添加模板
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[1]/span/div/div/button").click()
            #输入模板名称
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[2]/div/div/div[1]/div[2]/div[1]/div/pre/div[1]/p").send_keys("自动化测试"+WJDriver.name)
            #输入模板内容
        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div")))
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div").click()
            #点击保存
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[5]").click()
        sleep(1)
            #点击添加到公有库
        #wait.until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[2]/form/div[4]/div/div/div/div/label/span[1]/input")))
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[2]/form/div[4]/div/div/div/div/label/span[1]/input").click()
            #点击保存
        #wait.until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[2]")))
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[2]").click()
            #点击取消
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[1]").click()
            #点击关闭
        sleep(2)
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[1]").click()
        print("模板广场页面：公有库2正常")
        #333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
        #不填写模板名称，填写分类
            # 点击添加模板
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[1]/span/div/div/button").click()
        sleep(1)
            # 输入模板内容
        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div")))
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div").click()
            # 点击保存
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[5]").click()
            # 弹出窗口，输入分类
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[2]/form/div[2]/div/div[2]/div/div/div/div/span[1]/input").send_keys("自动化测试")
        # self.driver.find_element(By.XPATH,"/html/body/div[6]/div/div/div/div[2]/div/div/div/div[3]/div").click()
            # 点击添加到公有库
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[2]/form/div[4]/div/div/div/div/label/span[1]/input").click()
        sleep(1)
            # 点击保存
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[2]").click()
        sleep(2)
            #点击取消
        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[1]")))
        wait.click()
        #self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[1]").click()
            # 点击关闭
        sleep(1)
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[1]").click()
        print("模板广场页面：公有库3正常")
        #444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
        #点击模板96和全部
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/form/div[1]/div[2]/div/div/div/div/div/div/span[7]").click()
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/form/div[1]/div[2]/div/div/div/div/div/div/span[1]").click()
        print("点击模板正常")
        #555555555555555555555555555555555555555555555555555555555555555555555555555555555555555

        #2.测试私有库#############################################################################
        # 正确填写模板名称，点击搜索模板
            #点击私有库
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[3]/div/div[1]/div[1]/div/div[2]/div").click()
            # 输入要搜索的模板
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[2]/div/div/div/div/div/span/span/input").send_keys("测试")
            # 点击搜模板
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[2]/div/div/div/div/div/span/span/span/button").click()
        # 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
        # 点击添加模板，进入模板编辑页面编辑好内容，点击保存到公有库，点击保存，填写提示框再点击保存
            # 点击添加模板
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[1]/span/div/div/button").click()
            # 输入模板名称
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[2]/div/div/div[1]/div[2]/div[1]/div/pre/div[1]/p").send_keys("自动化测试" + WJDriver.name)
            # 输入模板内容
        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div")))
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div").click()
            # 点击保存
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[5]").click()
            # 弹出窗口，输入分类
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[2]/form/div[2]/div/div[2]/div/div/div/div/span[1]/input").send_keys("自动化测试")
        # self.driver.find_element(By.XPATH,"/html/body/div[6]/div/div/div/div[2]/div/div/div/div[3]/div").click()
        sleep(1)
            # 点击保存
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[2]").click()
            # 点击关闭
        sleep(1)
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[1]").click()
        print("模板广场页面：私有库1正常")

        #222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
        #填写模板名称，不填写分类
        # 点击添加模板
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[1]/span/div/div/button").click()
        # 输入模板名称
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[2]/div/div/div[1]/div[2]/div[1]/div/pre/div[1]/p").send_keys("自动化测试" + WJDriver.name)
        # 输入模板内容
        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div")))
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div").click()
        # 点击保存
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[5]").click()
        sleep(1)
        # 点击保存
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[2]").click()
        # 点击取消
        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[1]")))
        wait.click()
        # 点击关闭
        sleep(1)
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[1]").click()
        print("模板广场页面：私有库2正常")
        #333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
        #不填写模板名称，填写分类
            # 点击添加模板
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[1]/span/div/div/button").click()
            # 输入模板内容
        sleep(1)
        wait = WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div")))
        wait.click()
        #self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div/dl[1]/div/div[1]/dd/div").click()
            # 点击保存
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[5]").click()
            # 弹出窗口，输入分类
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[2]/form/div[2]/div/div[2]/div/div/div/div/span[1]/input").send_keys("自动化测试")
        sleep(1)
            # 点击保存
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[2]").click()
            # 点击取消
        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[4]/div/div/div[2]/div/div[2]/div[3]/button[1]")))
        wait.click()
            # 点击关闭
        sleep(1)
        self.driver.find_element(By.XPATH,"/html/body/div[5]/div/div[3]/div/div/div/div/div[2]/div[1]/div[2]/div/button[1]").click()
        print("模板广场页面：私有库3正常")

        #444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
        #点击自动化测试和全部
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/form/div[1]/div[2]/div/div/div/div/div/div/span[13]").click()
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/form/div[1]/div[2]/div/div/div/div/div/div/span[1]").click()
        print("点击模板正常")
        print("模板广场页面正常..................")
        #555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
        #self.driver.quit()
# template=WJTemplate()
# template.TestByTemplateFunction()